package com.example.springjpa.controller;

import com.example.springjpa.model.Clazz;
import com.example.springjpa.repository.ClazzRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/clazz")
public class ClazzController {

    private final ClazzRepository clazzRepository;

    public ClazzController(ClazzRepository clazzRepository) {
        this.clazzRepository = clazzRepository;
    }

    @PostMapping
    public Clazz add(Clazz clazz) {
        return clazzRepository.save(clazz);
    }

    @GetMapping
    public List<Clazz> list() {
        return clazzRepository.findAll();
    }
}
